package com.caine.common.entity;

import com.caine.common.constant.Constant;
import java.io.Serializable;

/**
 * @Author: CaineZhu
 * @Description:
 * @Date: Created in 17:33 2019/10/28
 * @Modified By:
 */
public class R<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> R success() {
        return success("SUCCESS");
    }

    public static <T> R success(String msg) {
        return normal(Constant.SUCCESS, msg, null);
    }

    public static <T> R success(T data) {
        return normal(Constant.SUCCESS, "SUCCESS", data);
    }

    public static <T> R error(String msg) {
        return normal(Constant.ERROR, msg, null);
    }

    public static <T> R error(T data) {
        return normal(Constant.ERROR, "error", data);
    }

    public static <T> R unauthorized(String msg) {
        return normal(Constant.UNAUTHORIZED, msg, null);
    }

    public static <T> R normal(int code, String msg, T data) {
        return new R(code, msg, data);
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
